/**
 * 1
 *  
 * @Author : roryrywang
 * @DateTime : 24-9-5 下午4:00
 */

#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int n;
    cin >> n;
    int amin1 = 0x3f3f3f3f;
    int amin2 = 0x3f3f3f3f;
    int aidx1 = -1;
    int aidx2 = -1;
    int bmin1 = 0x3f3f3f3f;
    int bmin2 = 0x3f3f3f3f;
    int bidx1 = -1;
    int bidx2 = -1;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        if (a < amin1) {
            amin2 = amin1;
            aidx2 = aidx1;
            amin1 = a;
            aidx1 = i;
        } else if (a < amin2) {
            amin2 = a;
            aidx2 = i;
        }
    }
    for (int i = 0; i < n; ++i) {
        int b;
        cin >> b;
        if (b < bmin1) {
            bmin2 = bmin1;
            bidx2 = bidx1;
            bmin1 = b;
            bidx1 = i;
        } else if (b < bmin2) {
            bmin2 = b;
            bidx2 = i;
        }
    }
    if (aidx1 != bidx1) {
        cout << max(amin1, bmin1);
    } else {
        cout << min(amin1 + bmin1, min(max(amin1, bmin2), max(amin2, bmin1)));
    }
    return 0;
}